package com.cl.code.generate.source.controller.entity;

import java.util.HashMap;
import java.util.Map;

public class JavaToTSMapper {

    private static final Map<String, String> typeMapping = new HashMap<>();

    static {
        // 基础类型
        typeMapping.put("byte", "number");
        typeMapping.put("short", "number");
        typeMapping.put("int", "number");
        typeMapping.put("long", "string");
        typeMapping.put("float", "number");
        typeMapping.put("double", "number");
        typeMapping.put("boolean", "boolean");
        typeMapping.put("char", "string");

        // 包装类型
        typeMapping.put("java.lang.Byte", "number");
        typeMapping.put("java.lang.Short", "number");
        typeMapping.put("java.lang.Integer", "number");
        typeMapping.put("java.lang.Long", "string");
        typeMapping.put("java.lang.Float", "number");
        typeMapping.put("java.lang.Double", "number");
        typeMapping.put("java.lang.Boolean", "boolean");
        typeMapping.put("java.lang.Character", "string");

        // 常见对象
        typeMapping.put("java.lang.String", "string");
        typeMapping.put("java.math.BigDecimal", "number");
        typeMapping.put("java.math.BigInteger", "number");
        typeMapping.put("java.lang.Object", "any");
    }

    public static boolean containsJavaType(String javaType) {
        return typeMapping.containsKey(javaType);
    }

    public static String mapJavaTypeToTypeScript(String javaType) {
        return typeMapping.getOrDefault(javaType, "any");
    }

}
